﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace YougeBookmark.Models
{
    /// <summary>
    /// 书签-标签关联实体
    /// 对应数据库BookmarkTags表
    /// </summary>
    [Table("BookmarkTags")]
    public class BookmarkTag
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [Required(ErrorMessage = "必须关联书签")]
        public int BookmarkId { get; set; }

        [Required(ErrorMessage = "必须关联标签")]
        public int TagId { get; set; }

        [Required]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public DateTime CreatedAt { get; set; }

        // 导航属性 - 书签实体
        [ForeignKey("BookmarkId")]
        public virtual Bookmark Bookmark { get; set; }

        // 导航属性 - 标签实体
        [ForeignKey("TagId")]
        public virtual Tag Tag { get; set; }

        /// <summary>
        /// 格式化关联信息（调试用，不映射到数据库）
        /// </summary>
        [NotMapped]
        public string DebugInfo =>
            $"Bookmark:{BookmarkId}-Tag:{TagId} @{CreatedAt:yyyy-MM-dd HH:mm}";
    }
}